home *** CD-ROM | disk | FTP | other *** search
- Path: mayne.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Settle a bet please
- Date: 29 Mar 1996 10:06:53 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4jh8rtINNosd@mayne.ugrad.cs.ubc.ca>
- References: <4jfopb$o9n@news1.sympatico.ca>
- NNTP-Posting-Host: mayne.ugrad.cs.ubc.ca
-
- In article <4jfopb$o9n@news1.sympatico.ca>,
- Gisele Swinson <gisele.swinson@sympatico.ca> wrote:
- >In C language, how do they calculate the length of an array.
- >
- >example
- >
- >To declare a string "My Name"
- >
- >is it char name[7] = "My Name"
- >or
- >is it chat Name[8] = "My Name"
- >
- >There is a battle in my class whether to include the NULL in the
- >array size.
-
- It's a null character, not the NULL pointer.
-
- >I would appreciate any input you might have.
-
- The proper way is to leave the size out unless you will be writing some other
- string into the same field.
-
- char name[] = "My Name";
-
-
- If you give a specific size, you must include storage for the terminating zero,
- IF YOU EXPECT ``name'' to be a STRING.
-
- If you don't care about name being a string, you can declare the size as 7. The
- standard allows that leeway, I think (I would have to check!). In that case,
- you just have an array of the characters { 'M', 'y', 'n', 'a', 'm', 'e' }. It
- is not a string, and should not be used as an argument to string manipulating
- functions.
-
- So nobody has won the bet, because you have not decided whether you are sizing
- a string or a plain array.
- --
-
-